// component/hours/hours.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    hoursPrice:Number,
    jthjDataCate:Object,
    hoursid:String,
    name:String
  },

  /**
   * 组件的初始数据
   */
  data: {
    isRuleTrue: false,
    num: 4,
    minusStatus: 'disable',
    hoursPriceTotal:0
  },
  ready() {
    this.animation = wx.createAnimation()
  },
  /**
   * 组件的方法列表
   */
  methods: {
    translate: function () {
      console.log(2)
      this.setData({
        isRuleTrue: true
      })
      this.animation.translate(-245, 0).step()
      this.setData({ animation: this.animation.export() })
    },

    success: function () {
      let hours=this.data.num
      let price = hours * this.data.hoursPrice
      console.log(price)
      this.setData({
        isRuleTrue: false,
        hoursPriceTotal:price
      })
      wx.setStorageSync("jthj", { "name":this.data.name,"id":this.data.hoursid,"data": this.data.jthjDataCate,"money":this.data.hoursPriceTotal,"hours":hours})
      this.animation.translate(0, 0).step()
      this.setData({ animation: this.animation.export() })
      this.triggerEvent("hoursPrice", this.data.hoursPriceTotal)
    },
    cancel:function(){
      this.setData({
        isRuleTrue:false,
        hoursPrice:0
      })
      wx.removeStorageSync("jthj")
      this.triggerEvent('cancel', false);
      this.animation.translate(0,0).step()
      this.setData({ animation: this.animation.export() })
      this.triggerEvent("hoursPrice",0)
    },
    tryDriver: function () {
      this.setData({
        background: "#89dcf8"
      })
    },
    /*点击减号*/
    bindMinus: function () {
      var num = this.data.num;
      if (num > 4) {
        num--;
      }
      var minusStatus = num > 4 ? 'normal' : 'disable';
      this.setData({
        num: num,
        minusStatus: minusStatus
      })
    },
    /*点击加号*/
    bindPlus: function () {
      var num = this.data.num;
      num++;
      var minusStatus = num > 1 ? 'normal' : 'disable';
      this.setData({
        num: num,
        minusStatus: minusStatus
      })
    },
    /*输入框事件*/
    bindManual: function (e) {
      var num = e.detail.value;
      var minusStatus = num > 1 ? 'normal' : 'disable';
      this.setData({
        num: num,
        minusStatus: minusStatus
      })
    },
    choose:function(e){
      console.log(e)
      let status = e.currentTarget.dataset.status
      let index = e.currentTarget.dataset.index
      let pid =e.currentTarget.dataset.pid
      let list =this.data.jthjDataCate
      for (let i in list){
        for(let k in list[i].cate){
          if (k == index && list[i].id==pid) {
            if (status == 1) {
              list[i].cate[k].status = 0
            } else {
              list[i].cate[k].status = 1
            }
          }
        }
      }
      console.log(list)
      this.setData({
        jthjDataCate:list
      })
    }
  }
})
